using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.BusinessObjects;

namespace TrainingManagement.api.Models.Data.CRUD.Position
{
    public class PositionSkillSetInsertDataSource : NonQuerySource<List<PositionSkillSetDto>>
    {
        public override bool Execute(List<PositionSkillSetDto> request)
        {
            const string insertPositionSkillSet = "dbo.training_api_PositionSkillSetInsert";

            return 
                SqlHelper.ExecuteBulkNonQuery(
                    ConnectionStrings.TrainingDb,
                    CommandType.StoredProcedure,
                    insertPositionSkillSet,
                    request,
                    item =>
                        {
                            var parameters = new SqlParameter[2];
                            parameters[0] = new SqlParameter("@PositionID", SqlDbType.Int){Value = item.PositionId};
                            parameters[1] = new SqlParameter("@SkillSetID", SqlDbType.Int){Value = item.SkillSetId};
                            return parameters;
                        });
        }

        public bool Execute(PositionSkillSetDto request)
        {
            return Execute(new List<PositionSkillSetDto> {request});
        }
    }
}